package Servlets.employer;

import Dao.EmployerDaoimpl;
import Entity.Employer;
import Entity.Seeker;
import Service.FettleServiceimpl;
import Service.SeekerServiceimpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/offer")

public class Offer extends HttpServlet {

    private static final long serialVersionUID = 1L;
    public Offer() {
        super();
    }


    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

// TODO Auto-generated method stub

        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");

        response.setContentType("text/html;charset=UTF-8");

        String sid =request.getParameter("sid");

        int eid = (int) request.getSession().getAttribute("seid");
        EmployerDaoimpl edl=new EmployerDaoimpl();
        SeekerServiceimpl se=new SeekerServiceimpl();
        int tsid=Integer.parseInt(sid);
        String cw=null;
        FettleServiceimpl del=new FettleServiceimpl();
        try {
            Employer em=edl.SearchById(eid);
            String ename=em.getEname();
            String econtact=em.getContacter();
            String ep=em.getPhone();
            Seeker sm=se.SearchById(tsid);
            String sname=sm.getSname();
            String sphone=sm.getSphone();
            cw= del.offer(eid,tsid,ename,econtact,ep,sname,sphone);


            if( cw.equals("邀请成功") ) {

                request.getRequestDispatcher("/Jobservlet").forward(request, response);

            } else if( cw.equals("已邀请")) {

                request.setAttribute("cw2", "已邀请");

                request.getRequestDispatcher("/Jobservlet").forward(request, response);

            }

        } catch (Exception e) {

// TODO Auto-generated catch block
            System.out.println("错误");
            e.printStackTrace();

        }

    }







    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

// TODO Auto-generated method stub

        doGet(request, response);

    }


}